package com.wsg.lightaccounting.Adapter;

import android.content.Context;
import android.content.pm.LabeledIntent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wsg.lightaccounting.ClassConversion;
import com.wsg.lightaccounting.Model.DateSum;
import com.wsg.lightaccounting.R;

import java.util.List;

/**
 * Created by dell-pc on 2016/11/21.
 */

public class DateSumListAdapte extends BaseAdapter{
    private Context context;
    private List<DateSum> dateSa;

    public DateSumListAdapte(Context context, List<DateSum> dateSa) {
        this.context = context;
        this.dateSa = dateSa;
    }

    public void setDateSa(List<DateSum> dateSa) {
        this.dateSa = dateSa;
    }

    @Override
    public int getCount() {
        return dateSa.size();
    }

    @Override
    public Object getItem(int position) {
        return dateSa.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Item item;
        if (convertView == null){
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.line_fragment_list_layout,null);
            item = new Item((TextView) convertView.findViewById(R.id.line_list_date),(TextView)convertView.findViewById(R.id.line_list_dateSum));
            convertView.setTag(item);
        }
        else{
            item = (Item) convertView.getTag();
        }
        item.date.setText(ClassConversion.dateToString(dateSa.get(position).getDate(),"yyyy/mm/dd"));
        item.sum.setText(String.valueOf(dateSa.get(position).getSum()));
        return convertView;
    }
    class Item{
        protected TextView date;
        protected TextView sum;

        public Item(TextView date, TextView sum) {
            this.date = date;
            this.sum = sum;
        }
    }
}
